package com.ruoyi.ly.mapper;

import com.github.pagehelper.Page;
import com.ruoyi.ly.domain.Project;
import com.ruoyi.ly.domain.SpaceBan;
import com.ruoyi.ly.domain.dto.PageSpaceBanDTO;
import com.ruoyi.ly.domain.dto.SpaceBanAddDTO;
import com.ruoyi.ly.domain.vo.*;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SpaceBanMapper {

    //分页查询
    Page<PageProjectVO> pageQuery(PageSpaceBanDTO pageSpaceBanDto);

    //添加楼栋
    void insert(SpaceBan spaceBan);

    //删除楼栋
    @Delete("delete from space_ban where ban_id = #{banId}")
    void delete(Integer banId);

    //查询所有楼栋信息
    @Select("select sb.ban_name,sb.ban_address,sb.ban_numbers,sb.ban_area,sb.group_id,p.project_name from space_ban sb left join project p on sb.project_id = p.id")
    List<PageSpaceBanVO> findAll();

    //修改楼栋信息
    void update(SpaceBan spaceBan);

    //根据id查询楼栋信息
    @Select("select sb.ban_id,sb.ban_name,sb.project_id,p.project_name,sb.ban_address,sb.ban_numbers,sb.ban_area,sb.imgs from space_ban sb " +
            "left join project p on sb.project_id = p.id where sb.ban_id = #{banId}")
    SpaceBanUpdateVO selectById(Long banId);

    //根据项目id查询所属楼栋
    @Select("select ban_id,ban_name from space_ban where project_id = #{projectID}")
    List<WorkSpaceAddBanVO> slectByProjectId(Long projectId);


    //根据项目id和楼栋id查询所属楼层
    @Select("select floor_id,floor_number from space_floor where project_id = #{projectId} and ban_id = #{banId} ")
    List<WorkSpaceAddFloorVO> selectByProjectAndBanId(@Param("projectId") Long projectId , @Param("banId") Long banId);

    //查询所有的楼栋
    @Select("select * from space_ban")
    List<SpaceBan> selectAllBan();

    //查询所有的项目
    @Select("select * from project")
    List<Project> selectAllProject();

    //判断楼栋名是否重复
    @Select("select count(1) from space_ban where ban_name = #{banName}")
    Integer selectByRepeatBanName(String banName);

    @Select("select ban_name from space_ban where ban_id = #{banId}")
    String getName(Long banId);
}
